<?php
namespace App\Http\Controllers\Admin;
use App\Http\Controllers\Controller;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Auth;
use Illuminate\Support\Facades\DB;
use Illuminate\Support\Facades\Session;


class LoginController extends Controller{
    public function login(){
        return view('admin.login.login');
    }
    public function verification(Request $request){
        $params = $request->input();
        $value = session('mikcaptcha');
        $res = DB::table('admin_user')->where('account',$params['account'])->first();
        if($res){
            $pwd = DB::table('admin_user')->where([
                ['account',$params['account']],
                ['password',md5($params['password'])]
            ])->get();
            if(count($pwd)>0){
                if($value==$params['captcha']){
                    foreach ($pwd as $val){
                        $number = ceil($val->number)+1;
                    }
                    DB::table('admin_user')->where([
                        ['account',$params['account']],
                        ['password',md5($params['password'])]
                    ])->update(['number'=>$number]);
                    Session::put('admin_user',$pwd);
                    return json_encode(200);
                }else{
                    return json_encode(402);
                }
            }else{
                return json_encode(403);
            }
        }else{
            return json_encode(404);
        }
    }
}